package com.southwind.controller;

import com.southwind.entity.DormitoryAdmin;
import com.southwind.service.DormitoryAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


/**
 * 宿舍管理员消息
 */
@Controller
@RequestMapping("/dormitoryAdmin")
public class DormitoryAdminController {

    @Autowired
    private DormitoryAdminService dormitoryAdminService;

    @GetMapping("/list")
    public ModelAndView modelAndView() {
        ModelAndView m = new ModelAndView();
        m.setViewName("adminmanager");
        m.addObject("list", this.dormitoryAdminService.list());
        return m;
    }

    @PostMapping("/search")
    public ModelAndView search(String key, String value) {
        ModelAndView m = new ModelAndView();
        m.setViewName("adminmanager");
        m.addObject("list", this.dormitoryAdminService.search(key, value));
        return m;
    }

    @PostMapping("/save")
    public String save(DormitoryAdmin dormitoryAdmin)
    {
        this.dormitoryAdminService.save(dormitoryAdmin);
        return "redirect:/dormitoryAdmin/list"; //重定向
    }

    @PostMapping("/delete")
    public String delete(Integer id){
        this.dormitoryAdminService.delete(id);
        return "redirect:/dormitoryAdmin/list"; //重定向
    }

    @PostMapping("/update")
    public String update(DormitoryAdmin dormitoryAdmin){
        this.dormitoryAdminService.update(dormitoryAdmin);
        return "redirect:/dormitoryAdmin/list";//重定向
    }
}
